package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()) {
            Statement satatement = connection.createStatement();
            String sql = "select count(*) count " +
                    "from class c " +
                    "join student s on c.id = s.class_id " +
                    "where c.name = '1年级1班'";
            ResultSet resultSet = satatement.executeQuery(sql);


            while (resultSet.next()){
                int count = resultSet.getInt("count");
                System.out.println(count);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
